home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / graphic / fgdemo10.zip / FUNDMTLS.C < prev    next >
Text File  |  1991-10-05  |  14KB  |  617 lines

  1. /**********************************************************************\
  2. *                                                                      *
  3. *  fundmtls.c -- graphics fundamentals: points, lines, rects, etc.     *
  4. *                                                                      *
  5. \**********************************************************************/
  6.  
  7. #include "defs.h"
  8.  
  9. /**********************************************************************\
  10. *                                                                      *
  11. *  do_circles -- draw a bunch of circles                               *
  12. *                                                                      *
  13. \**********************************************************************/
  14.  
  15. do_circles()
  16. {
  17.    register int i;
  18.    int x1,x2,y1,y2;
  19.  
  20.    /* establish clipping limits */
  21.  
  22.    x1 = 0;
  23.    x2 = xlimit;
  24.    y1 = menu_bottom;
  25.    y2 = ylimit;
  26.  
  27.    fg_setclip(x1,x2,y1,y2);
  28.  
  29.    /* clear bottom part of screen */
  30.  
  31.    fg_mousevis(OFF);
  32.    if (mode06 || mode11)
  33.      fg_setcolor(0);
  34.    else
  35.      fg_setcolor(1);
  36.    fg_rect(x1,x2,y1,y2);
  37.  
  38.    /* move to the center of the screen */
  39.  
  40.    x1 = xlimit / 2;
  41.    y1 = (ylimit + menu_bottom) / 2;
  42.    fg_move(x1,y1);
  43.  
  44.    /* draw concentric circles */
  45.  
  46.    x2 = 4;
  47.    fg_setcolor(15);
  48.    for (i = 0; i < 25; i++)
  49.    {
  50.       fg_circle(x2);
  51.       x2 += 8;
  52.    }
  53.  
  54.    /* wait for a keystroke */
  55.  
  56.    fg_mousevis(ON);
  57.    wait_for_keystroke();
  58.  
  59.    /* restore clipping limits */
  60.  
  61.    fg_setclip(0,fg_getmaxx(),0,fg_getmaxy());
  62.  
  63.    /* restore the screen and return to the menu */
  64.  
  65.    fg_mousevis(OFF);
  66.    fg_restore(0,xlimit,menu_bottom,ylimit);
  67.  
  68.    fg_mousevis(ON);
  69.    redraw = TRUE;
  70.  
  71.    return(OK);
  72. }
  73.  
  74. /**********************************************************************\
  75. *                                                                      *
  76. *  do_clip -- do those lines, clipped to a small rectangle             *
  77. *                                                                      *
  78. \**********************************************************************/
  79.  
  80. int do_clip()
  81. {
  82.    register int i,j;
  83.    int x1,x2,y1,y2;
  84.    int xinc;
  85.  
  86.    static int lcolor[] = {2,1,9,11,11,9,1,2};
  87.  
  88.    /* establish clipping limits - small rectangle in middle of screen */
  89.  
  90.    fg_setclip(135,510,menu_bottom+55,ylimit-55);
  91.  
  92.    /* clear bottom of screen */
  93.  
  94.    fg_mousevis(OFF);
  95.    fg_restore(0,xlimit,menu_bottom,ylimit);
  96.    fg_setcolor(15);
  97.    fg_rect(135,510,menu_bottom+55,ylimit-55);
  98.  
  99.    /* draw horizontal lines */
  100.  
  101.    fg_setcolor(0);
  102.    for (i = menu_bottom; i < ylimit; i+=40)
  103.    {
  104.       for (j = 0; j < 8; j++)
  105.       {
  106.          if (mode14 || mode16)
  107.             fg_setcolor(lcolor[j]);
  108.  
  109.          y1 = i + 3*j;
  110.          fg_move(0,y1);
  111.          fg_draw(xlimit,y1);
  112.  
  113.       }
  114.    }
  115.  
  116.    /* draw vertical lines */
  117.  
  118.    y1 = menu_bottom;
  119.    y2 = ylimit;
  120.    for (i = 0; i < 640; i+=60)
  121.    {
  122.       for (j = 0; j < 8; j++)
  123.       {
  124.          if (mode14 || mode16)
  125.             fg_setcolor(lcolor[j]);
  126.  
  127.          x1 = i + 3*j;
  128.          fg_move(x1,y1);
  129.          fg_draw(x1,y2);
  130.       }
  131.    }
  132.  
  133.    /* draw red diagonal lines */
  134.  
  135.    y1 = menu_bottom;
  136.    y2 = ylimit;
  137.    xinc = ylimit - menu_bottom;
  138.    fg_setcolor(12);
  139.    for (x1 = -640; x1 < 640; x1+=60)
  140.    {
  141.       x2 = x1 + xinc;
  142.       fg_move(x1,y1);
  143.       fg_draw(x2,y2);
  144.    }
  145.  
  146.    y1 = menu_bottom;
  147.    y2 = ylimit;
  148.    xinc = ylimit - menu_bottom;
  149.  
  150.    /* draw red diagonal lines */
  151.  
  152.    fg_setcolor(4);
  153.    for (x1 = 0; x1 < 1280; x1+=60)
  154.    {
  155.       x2 = x1-xinc;
  156.       fg_move(x1,y1);
  157.       fg_draw(x2,y2);
  158.    }
  159.  
  160.    /* wait for a keystroke or mouse button */
  161.  
  162.    fg_mousevis(ON);
  163.    wait_for_keystroke();
  164.  
  165.    /* clear the screen and return to the menu */
  166.  
  167.    fg_mousevis(OFF);
  168.    fg_setclip(0,fg_getmaxx(),0,fg_getmaxy());
  169.    fg_restore(0,xlimit,menu_bottom,ylimit);
  170.  
  171.    fg_mousevis(ON);
  172.    redraw = TRUE;
  173.    return(OK);
  174. }
  175.  
  176. /**********************************************************************\
  177. *                                                                      *
  178. *  do_ellipses -- draw a bunch of elipses                              *
  179. *                                                                      *
  180. \**********************************************************************/
  181.  
  182. do_ellipses()
  183. {
  184.    register int i;
  185.    int x1,x2,x3,y1;
  186.  
  187.    /* clear the screen */
  188.  
  189.    fg_mousevis(OFF);
  190.    if (mode06 || mode11)
  191.      fg_setcolor(1);
  192.    else
  193.      fg_setcolor(9);
  194.    fg_rect(0,xlimit,menu_bottom,ylimit);
  195.  
  196.    /* move to the center of the screen */
  197.  
  198.    x1 = xlimit / 2;
  199.    y1 = (ylimit + menu_bottom) / 2;
  200.    fg_move(x1,y1);
  201.  
  202.    /* draw concentric ellipses */
  203.  
  204.    x2 = 4;
  205.    x3 = 1;
  206.    fg_setcolor(0);
  207.    for (i = 0; i < 80; i++)
  208.    {
  209.       fg_ellipse(x2,x3);
  210.       x2 += 3;
  211.       x3++;
  212.    }
  213.  
  214.    /* wait for a keystroke or mouse button */
  215.  
  216.    fg_mousevis(ON);
  217.    wait_for_keystroke();
  218.  
  219.    /* restore the screen and return to the menu */
  220.  
  221.    fg_mousevis(OFF);
  222.    fg_restore(0,xlimit,menu_bottom,ylimit);
  223.  
  224.    fg_mousevis(ON);
  225.    redraw = TRUE;
  226.  
  227.    return(OK);
  228. }
  229.  
  230. /**********************************************************************\
  231. *                                                                      *
  232. *  do_lines -- draw lines to create a plaid pattern                    *
  233. *                                                                      *
  234. \**********************************************************************/
  235.  
  236. do_lines()
  237. {
  238.    register int i,j;
  239.    int x1,x2,y1,y2;
  240.    int xinc;
  241.  
  242.    static int lcolor[] = {2,1,9,11,11,9,1,2};
  243.  
  244.    /* clear bottom part of screen */
  245.  
  246.    fg_mousevis(OFF);
  247.    fg_setcolor(15);
  248.    fg_rect(0,xlimit,menu_bottom,ylimit);
  249.  
  250.    /* draw horizontal lines */
  251.  
  252.    fg_setcolor(0);
  253.    for (i = menu_bottom; i < ylimit; i+=40)
  254.    {
  255.       for (j = 0; j < 8; j++)
  256.       {
  257.          if (mode14 || mode16)
  258.             fg_setcolor(lcolor[j]);
  259.  
  260.          y1 = i + 3*j;
  261.          fg_move(0,y1);
  262.          fg_draw(xlimit,y1);
  263.  
  264.       }
  265.    }
  266.  
  267.    /* draw vertical lines */
  268.  
  269.    y1 = menu_bottom;
  270.    y2 = ylimit;
  271.    for (i = 0; i < 640; i+=60)
  272.    {
  273.       for (j = 0; j < 8; j++)
  274.       {
  275.          if (mode14 || mode16)
  276.             fg_setcolor(lcolor[j]);
  277.  
  278.          x1 = i + 3*j;
  279.          fg_move(x1,y1);
  280.          fg_draw(x1,y2);
  281.       }
  282.    }
  283.  
  284.    /* draw red diagonal lines */
  285.  
  286.    y1 = menu_bottom;
  287.    y2 = ylimit;
  288.    xinc = ylimit - menu_bottom;
  289.    fg_setcolor(12);
  290.    for (x1 = -640; x1 < 640; x1+=60)
  291.    {
  292.       x2 = x1 + xinc;
  293.       fg_move(x1,y1);
  294.       fg_draw(x2,y2);
  295.    }
  296.  
  297.    y1 = menu_bottom;
  298.    y2 = ylimit;
  299.    xinc = ylimit - menu_bottom;
  300.  
  301.    /* draw red diagonal lines */
  302.  
  303.    fg_setcolor(12);
  304.    for (x1 = 0; x1 < 1280; x1+=60)
  305.    {
  306.       x2 = x1 - xinc;
  307.       fg_move(x1,y1);
  308.       fg_draw(x2,y2);
  309.    }
  310.  
  311.    /* wait for a keystroke or mouse button */
  312.  
  313.    fg_mousevis(ON);
  314.    wait_for_keystroke();
  315.  
  316.    /* restore the screen and return to the menu */
  317.  
  318.    fg_mousevis(OFF);
  319.    fg_restore(0,xlimit,menu_bottom,ylimit);
  320.  
  321.    fg_mousevis(ON);
  322.    redraw = TRUE;
  323.  
  324.    return(OK);
  325. }
  326.  
  327. /**********************************************************************\
  328. *                                                                      *
  329. *  do_paint -- draw a quartered circle, then paint around it           *
  330. *                                                                      *
  331. \**********************************************************************/
  332.  
  333. do_paint()
  334. {
  335.    int x1,x2,y1,y2;
  336.  
  337.    /* restor the screen */
  338.  
  339.    fg_mousevis(OFF);
  340.    fg_restore(0,xlimit,menu_bottom,ylimit);
  341.  
  342.    /* draw a rectangle */
  343.  
  344.    y1 = menu_bottom + scale(20);
  345.    y2 = ylimit - scale(20);
  346.    x1 = 40;
  347.    x2 = xlimit - 40;
  348.  
  349.    if (mode06 || mode11)
  350.       fg_setcolor(0);
  351.    else
  352.       fg_setcolor(11);
  353.  
  354.    fg_rect(x1,x2,y1,y2);
  355.  
  356.    /* outline the rectangle */
  357.  
  358.    if (mode06 || mode11)
  359.       fg_setcolor(1);
  360.    else
  361.       fg_setcolor(0);
  362.    draw_box(x1,x2,y1,y2);
  363.  
  364.    y1 = (ylimit + menu_bottom) / 2;
  365.    x1 = xlimit / 2;
  366.